package com.example.design.filter.filter;

import com.example.design.DateUtils;
import com.example.design.filter.ScheduleFilter;
import com.example.design.filter.context.ScheduleContext;
import com.example.design.filter.context.ScheduleUser;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 请假
 */
public class LeaveFilter implements ScheduleFilter {

    public static final ScheduleFilter instance = new LeaveFilter();

    @Override
    public void filter(ScheduleContext context) {
        Date date = DateUtils.localDate2Date(context.getScheduleDate());
        List<ScheduleUser> scheduleUsers = context.getScheduleUsers();
        List<ScheduleUser> leaveUsers = scheduleUsers.parallelStream().filter(user -> user.getTags() != null && user.leaveToday(date)).collect(Collectors.toList());
        context.addRestUsers(leaveUsers);
    }
}
